package com.loginregister.web.old; /**
 * @author wzm
 * @create 2023-05-12 11:10
 */

import com.loginregister.utils.CodeUtils;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

//专门用来生成图片的servlet
@WebServlet("/code.jpg")
public class CodeServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        //生成验证码
        String s = CodeUtils.outputVerifyImage(150, 50, response.getOutputStream(), 4);
        //阿里云 腾讯云
        //将验证码存储到Session方便注册时与用户输入的验证码进行对比
        request.getSession().setAttribute("seesioncode",s);
    }
}
